<template>
    <div>我是首页</div>
    <button @click="logout" >退出登录</button>
</template>
<script setup lang="ts"> 
import {ref} from 'vue'
import {ElMessage} from 'element-plus'
import { useRouter } from 'vue-router'
import { AuthApi }from '@/api/auth'
const router = useRouter()
const logout = async () =>{
    // 清除token和用户信息
    const token = localStorage.getItem('token')
    if(token){
        await AuthApi.logout(token)
    }
    localStorage.removeItem('token')
    localStorage.removeItem('userInfo')
    // 提示用户退出登录
    ElMessage.success('退出登录成功')
    // 跳转到登录页
    setTimeout(() => {
        router.push('/new-login')
    }, 1000)
   
}
</script>
<style scoped>

</style>